#ifndef CDRAWPROPERTY_H
#define CDRAWPROPERTY_H

#include <QObject>
#include <QWidget>

typedef struct _DRAWPROPERTY
{
    QColor penColor;
    int penWidth;
    QFont font;
    _DRAWPROPERTY()
    :penColor(QColor())
    ,penWidth(2)
    ,font("Arial", 20)
    {}
}DRAWPROPERTY;

class CDrawProperty : public QWidget
{
    Q_OBJECT
public:
    enum drawType{
        Line,
        rect,
        text
    };

public:
    explicit CDrawProperty(QWidget *p, drawType type, QWidget *parent = nullptr);
    ~CDrawProperty();

    static void SetCurrentPropertyPtr(CDrawProperty* ptr);
    static CDrawProperty* GetCurrentPropertyPtr();
    static bool ShowCurrentWindow();
    static bool HideCurrentWindow();

    void ShowWidgetAndHideOtherGroupWidget();
    void SetProperty(const DRAWPROPERTY& property);
signals:
    void PropertyChange(const DRAWPROPERTY& property);
public Q_SLOTS:
    void PropertyColorSel(const QColor& color);
    //画笔宽度
    void PropertyWidth(int nWidth);
    //字体变化
    void PropertyFont(const QFont & font);
protected:
    virtual void mousePressEvent(QMouseEvent *event) override;
    virtual void enterEvent(QEvent *event) override;
    virtual void leaveEvent(QEvent *event) override;
    virtual void showEvent(QShowEvent *event) override;
    void paintEvent(QPaintEvent *) override;
private:
    void CreateWindow(drawType type);
    void CreateLinePropertyWindow();
    void CreateRectPropertyWindow();
    void CreateTextPropertyWindow();
    void Init();
private:
    drawType m_type;
    QWidget *m_p;
    bool m_showProperty;
    //static QList<CDrawProperty*> groupPropTypeList;
    static CDrawProperty* m_pCurrentDrawProperty;
    DRAWPROPERTY m_property;
    Qt::CursorShape m_nCursor;
};

#endif // CDRAWPROPERTY_H
